import json
from datetime import datetime, timedelta
from distutils.command.config import config
from idlelib.iomenu import encoding
import requests
import unittest
import config
from api.createOrUpdateSignExam import CreateOrUpdateSignExam
from scripts.test07_getExamExplain import ExamId


class TestCreateOrUpdateSignExam(unittest.TestCase):
    def setUp(self):
        self.session = requests.session()

    def tearDown(self):
        self.session.close()

    def test01_createOrUpdateSignExam(self):
        timenow = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        start_time = int((datetime.now() + timedelta(minutes=1)).timestamp() * 1000)
        endtime = int((datetime.now() + timedelta(hours=2)).timestamp() *1000)
        params = {
            "param": {
                "signExamDTO": {
                    "multipleClassSubjectList": [2],
                    "examType": 2,
                    "id": None,
                    "can_edit": "0",
                    "examName": f"C端诊断{timenow}",
                    "subjectId": 2,
                    "grade": 7,  # 请确保替换为实际值
                    "bookVersion": 2,  # 同上
                    "startTime": start_time,
                    "endTime": endtime,
                    "groupPaperList": [
                        {
                            "examResultLevelList": [
                                {"levelDataKey": 7, "levelPassScore": 10},
                                {"levelDataKey": 8, "levelPassScore": 20}
                            ],
                            "groupPaperId": 1001857,
                            "paperType": 1,
                            "nextVisibleScore": 30
                        },
                        {
                            "examResultLevelList": [
                                {"levelDataKey": 7, "levelPassScore": 10},
                                {"levelDataKey": 8, "levelPassScore": 20}
                            ],
                            "groupPaperId": 1001859,
                            "paperType": 1,
                            "nextVisibleScore": 30
                        },
                        {
                            "examResultLevelList": [
                                {"levelDataKey": 5, "levelPassScore": 20},
                                {"levelDataKey": 9, "levelPassScore": 30}
                            ],
                            "groupPaperId": 1000514,
                            "paperType": 2,
                            "nextVisibleScore": 0
                        }
                    ],
                    "temporaryStatus": False,
                    "suitStage": 1,
                    "feedbackTask": 0,
                    "examId": None,
                    "updator": "5267",
                    "operator": "5267"
                }
            },
            "client_id": "6",
            "service_name": "learnprod.ExamManageFacade.createOrUpdateSignExam",
            "strategy": "dubbo",
            "timestamp": 1668676167038,
            "token": config.TOKEN_RESULT[0].get("token")  # 请确保替换为实际值
        }
        responses = CreateOrUpdateSignExam().createOrUpdateSignExam(self.session,params)
        config.prints(responses)
        print(responses.json(encoding="utf-8"))
        self.assertEqual("1000001",responses.json()["code"])
        examId = ExamId().setexamId(responses.json()['data']['resultObject'])
        print(f"诊断id：{examId}")

